﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Configuration
{
    public class PLCConfig
    {
        static string ip=null;
        static int rack=-1;
        static int slot=-1;
        static ushort connectionType=0xff;

        const String sectionName = "PLC";

        public static Boolean HasSection
        {
            get
            {
                return InitConfig.hasSection(sectionName);
            }
        }

        public static string IP

        {
            get
            {
                if (ip == null)
                {
                    ip = InitConfig.getString(sectionName, "IP", "192.168.2.1");
                }
                return ip;
            }
        }

        public static ushort ConnectionType {
            get
            {
                if (connectionType == 0xff)
                {
                    String str = InitConfig.getString(sectionName, "connectionType", "3");
                    connectionType = ushort.Parse(str);
                }
                return connectionType;
                //return ConfigurationManager.AppSettings["DataSourceString"];
            }
        }
        public static int Rack {
            get
            {
                if (rack == -1)
                {
                    String str = InitConfig.getString(sectionName, "rack", "0");
                    rack = Int32.Parse(str);
                }
                return rack;
                //return ConfigurationManager.AppSettings["DataSourceString"];
            }

        }
        public static int Slot
        {
            get
            {
                if (slot == -1)
                {
                    String str = InitConfig.getString(sectionName, "slot", "1");
                    slot = Int32.Parse(str);
                }
                return slot;
                //return ConfigurationManager.AppSettings["DataSourceString"];
            }
        }

    }
}
